home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gnome2 / examples / bonobo / bonobo-application.py next >
Encoding:
Python Source  |  2009-03-14  |  1.9 KB  |  76 lines

  1. #! /usr/bin/env python
  2. import pygtk; pygtk.require("2.0")
  3.  
  4. import bonobo, sys
  5.  
  6. TEST_MESSAGE="test-message"
  7. CLOSURE_MESSAGE="closure-message"
  8.  
  9. def message_quit_cb(app_client, message, args):
  10.     bonobo.main_quit()
  11.  
  12. def message_cb(app_client, message, args):
  13.     print "message_cb: %s(%s)" % (message, ",".join(map(str, args)))
  14.     return 2*args[0]
  15.  
  16. def new_instance_cb(app, argc, argv):
  17.     print "new-instance received, argv:", argv
  18.     return argc
  19.  
  20. def closure_message_cb(app, arg_1, arg_2, user_data):
  21.     print "closure_message_cb: ", app, arg_1, arg_2, user_data
  22.     return arg_1 * arg_2
  23.  
  24.  
  25.  
  26. def main(argv):
  27.     msg_arg = 3.141592654
  28.  
  29.     bonobo.activate()
  30.  
  31.     app = bonobo.Application("Libbonobo-Test-Uniqapp")
  32.  
  33.     app.register_message(CLOSURE_MESSAGE,
  34.              "This is a test message",
  35.              float, (int, float),
  36.              closure_message_cb, "user-data")
  37.  
  38.     client = app.register_unique(app.create_serverinfo(("LANG",)))
  39.     if client is not None:
  40.     print "I am an application client."
  41.     app.unref(); del app
  42.     
  43.     msgdescs = client.msg_list()
  44.     for msgdesc in msgdescs:
  45.         print "Application supports message:", msgdesc
  46.  
  47.     print "Sending message string '%s' with argument %f" % (
  48.         TEST_MESSAGE, msg_arg)
  49.     retval = client.msg_send(TEST_MESSAGE, (msg_arg, "this is a string"))
  50.     print "Return value:", retval
  51.  
  52.     print "Sending message string '%s' with arguments %i and %f" % (
  53.         CLOSURE_MESSAGE, 10, 3.141592654)
  54.     retval = client.msg_send(CLOSURE_MESSAGE, (10, 3.141592654))
  55.     print "Return value: ", retval
  56.  
  57.     print "Sending new-instance, with argv"
  58.     i = client.new_instance(argv)
  59.     print "new-instance returned ", i
  60.  
  61.     print "Asking the server to quit"
  62.     client.msg_send("quit", ())
  63.     return
  64.     else:
  65.     print "I am an application server"
  66.     app.connect("message::test-message", message_cb)
  67.     app.connect("new-instance", new_instance_cb)
  68.     app.new_instance(argv)
  69.     app.connect("message::quit", message_quit_cb)
  70.  
  71.     bonobo.main()
  72.     app.unref()
  73.  
  74. main(sys.argv)
  75.  
  76.